//
//  SLDemoViewController.m
//  SLKit
//
//  Created by S_LINE on 2021/8/17.
//  Copyright © 2021 S_LINE. All rights reserved.
//

#import "SLDemoViewController.h"

#import "SLKit.h"

@interface SLDemoViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) SLTimer *timer1;
@property (nonatomic, strong) SLTimer *timer2;

@end

@implementation SLDemoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SL_SCREEN_WIDTH, SL_SCREEN_HEIGHT)];
    [self.view addSubview:tableView];
    tableView.delegate = self;
    tableView.dataSource = self;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"timerDemo"];
    
    [self demo];
}

- (void)demo
{
    self.timer1 = [SLTimer scheduledTimerWithTimeInterval:1 target:self repeats:YES action:^{
        NSLog(@"timer 1");
    }];
    
    self.timer2 = [SLTimer scheduledTimerWithTimeInterval:1.1 target:self repeats:NO action:^{
        NSLog(@"timer 2");
    }];
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10000;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"timerDemo"];
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"timerDemo"];
    }
    
    cell.textLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row];
    
    return cell;
}

- (void)dealloc
{
    NSLog(@"%s", __func__);
//    [self.timer1 invalidate];
//    [self.timer2 invalidate];
}

@end
